package com.tianshi.order.mapper;


import com.tianshi.entity.CartItems;
import com.tianshi.entity.OrderItems;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderItemMapper {
    @Select("select * from order_items where order_id = #{orderId}")
    List<OrderItems> selectByOrderId(Long orderId);

    @Insert("INSERT INTO order_items(order_id,product_id,product_name,product_image,product_price,quantity,total_price) VALUES(#{orderId},#{productId},#{productName},#{productImage},#{productPrice},#{quantity},#{totalPrice})")
    int insert(OrderItems orderItems);

    /**
     * 查询所有订单项
     * @return
     */
    @Select("SELECT * FROM order_items")
    List<OrderItems> selectAll();
    /**
     * 根据订单项id删除订单项
     */
    @Delete("DELETE FROM order_items WHERE item_id = #{itemId}")
    int deleteByItemId(Long itemId);

    /**
     * 根据订单id删除订单项
     * @param orderId
     * @return
     */
    @Delete("DELETE FROM order_items WHERE order_id = #{orderId}")
    int deleteByOrderId(Long orderId);

    /**
     * 根据订单项id查询订单项
     * @param orderId
     * @return
     */
    @Select("SELECT * FROM order_items WHERE item_id = #{itemId}")
    OrderItems selectByItemId(Long orderId);
}
